#include <iostream>
// 分别计算二叉树中叶子，度为1和度为2的节点的个数
struct Node
{
    char data;
    Node *left;
    Node *right;
    Node(char data) : data(data), left(nullptr), right(nullptr) {}
};

// 计算叶子节点数量
int LeafNodeQty(Node *root)
{
    if (!root)
        return 0;
    if (!root->left && !root->right)
        return 1;
    return LeafNodeQty(root->left) + LeafNodeQty(root->right);
}

// 计算度为1的数量
int OneNodeQty(Node *root)
{
    if (!root)
        return 0;
    if ((!root->left && root->right) || (root->left && !root->right))
        return 1;
    return OneNodeQty(root->left) + OneNodeQty(root->right);
}

// 计算度为2的节点数量
int TwoNodeQty(Node *root)
{
    if (!root)
        return 0;
    if (root->left && root->right)
        return 1;
    return TwoNodeQty(root->left) + TwoNodeQty(root->right);
}

int main()
{
    // 构建二叉树
    Node *root = new Node('A');
    root->left = new Node('B');
    root->right = new Node('C');
    root->left->left = new Node('D');
    root->left->right = new Node('E');
    root->right->left = new Node('F');
    // root->right->right = new Node('G');

    int LeafNode = LeafNodeQty(root);
    int OneNode = OneNodeQty(root);
    int TwoNode = TwoNodeQty(root);

    std::cout << "叶子 " << LeafNode << std::endl;
    std::cout << "度为1 " << OneNode << std::endl;
    std::cout << "度为2 " << TwoNode << std::endl;

    return 0;
}